package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcat.api.mysql.PmsProductAttributeValueApi;
import com.itcat.mapper.PmsProductAttributeValueMapper;
import com.itcat.mysql.pojo.CmsPrefrenceAreaProductRelation;
import com.itcat.mysql.pojo.PmsProductAttributeValue;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-04 0:06
 */
@DubboService
public class PmsProductAttributeValueApiImpl implements PmsProductAttributeValueApi {

    @Autowired
    private PmsProductAttributeValueMapper pmsProductAttributeValueMapper;


    /**
     * 保存商品参数及自定义规格属性
     * @param productAttributeValueList
     */
    @Override
    public void saveList(List<PmsProductAttributeValue> productAttributeValueList) {
        pmsProductAttributeValueMapper.batchInsert(productAttributeValueList);
    }

    /**
     * 通过productid商品参数及自定义规格属性
     * @param productId
     * @return
     */
    @Override
    public List<PmsProductAttributeValue> findByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductAttributeValue> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsProductAttributeValue::getProductId, productId);
        List<PmsProductAttributeValue> pmsProductAttributeValueList = pmsProductAttributeValueMapper.selectList(queryWrapper);
        return pmsProductAttributeValueList;
    }

    /**
     * 更新商品参数及自定义规格属性
     * @param productAttributeValueList
     */
    @Override
    public void updateList(List<PmsProductAttributeValue> productAttributeValueList) {
        pmsProductAttributeValueMapper.batchUpdate(productAttributeValueList);
    }

    /**
     * 删除响应商品id的数据
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<PmsProductAttributeValue> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, PmsProductAttributeValue::getProductId, productId);
        pmsProductAttributeValueMapper.delete(queryWrapper);
    }
}
